<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>
<body>
<input type="file" name="">
<img src=""alt ="未上传">

<script type="text/javascript" src="./ajax.js"></script>
<script type="text/javascript">
	let inp = document.querySelector('input')
	let img = document.querySelector('img')
	inp.onchange = function() {
		let fileParam = new FormData()
		fileParam.append('file',inp.files[0])
		/*let xhr = new XMLHttpRequest()
		xhr.open('post','http://47.104.167.34:8107/common/upload')
		xhr.send(fileParam)
		xhr.onreadystatechange =function() {
			if(xhr.readyState == 4){
				res = JSON.parse(xhr.responseText)
				console.log(res)
				let str = res.url
				img.src = str
			}
		}*/
		ajax({
			method:'post',
			url:'http://47.104.167.34:8107/common/upload',
			ContentType:'multipart/form-data',
			params:{
				'file':inp.files[0],
				// 'file2':inp.files[2]
			},
			success:function(res) {
				img.src=res.url
			}
		})
	}
</script>
</body>
</html>